<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
    <div class="easyui-panel"  style="padding:20px 80px;height:100%">
        <form id="element-add-form" method="post"  style="width:100%;margin:0 auto">
         
             <input  type="hidden" name="attribute" value="${attribute.id}">
          
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="name" style="width:100%" data-options="label:'名称:',required:true">
            </div>
            
           
            <#if attribute.name=="ComboBox"||attribute.name=="ComboTree">           
            <div style="margin-bottom:20px"  >
            	<input class="easyui-textbox" style="width:100%;height:32px;"  name="beasedata" id="beasedata"
            	data-options="label:'数据:',buttonText:'选择',prompt:'数据ID',onClickButton:onClickAttribute"
            	 >        
            </div>         
             </#if>
           
             <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="description" style="width:100%;height:80px" data-options="label:'备注:',multiline:'true'">
            </div>
            
        </form>
        <div style="text-align:center;padding:5px 0">
            <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm_AddBasedata()" style="width:80px">保存</a>          
        </div>
    </div>



    <div id="dlg" class="easyui-dialog" title="选择数据" style="width:500px;height:400px;"
            data-options="
            	closed:true,
                buttons: '#dlg-buttons'
            ">
      
      <table  class="easyui-treegrid" id="element-basedata-table"
				style="width:100%;height:100%;"
				data-options="
            	url:'${Domain}api/basedata',
                rownumbers: true,               
                animate: true,
                collapsible: true,
                fitColumns: true,
                pagination:true,
                loadMsg:'数据加载中……',
                method: 'post',
                idField: 'id',
                treeField: 'text',    
                onBeforeLoad: function(row,param){
                    if (!row) {    
                        param.id = 0;    
                    }
                }
            ">
				<thead>
					<tr>
						<th data-options="field:'',checkbox:true"></th>
						<th data-options="field:'id'">编号</th>
						<th data-options="field:'text',width:1">名称</th>						
					</tr>
				</thead>
		</table>
   
    </div>

	

    <div id="dlg-buttons">
        <a href="javascript:void(0)" id="element-linkbutton-select" class="easyui-linkbutton" data-options="iconCls:'icon-ok',disabled:true"  onclick="SelectBeasedata()">确定选择</a>
    </div>


<script>          
function submitForm_AddBasedata(){
	    $.messager.progress();
	     $('#element-add-form').form('submit',{
	        url:'${Domain}api/element/add',
	        onSubmit: function(param){   
	              var isValid = $(this).form('validate');
					if (!isValid){
						$.messager.progress('close');	// 如果表单是无效的则隐藏进度条
							return false;
					}	 	  		  				    
				},
				success:function(data){
				var json = eval('(' + data + ')');  // change the JSON string to javascript object
				if (json.status){
				 	$.messager.show({
		                title:'提示',
		                msg:'更新完成',
		                timeout:2000,
		                showType:'slide'
	            	});	
	            	$('#tngou-win').window('close');	
	            	$('#element-table').datagrid("reload");				 				           
				}else
				{
					$.messager.alert('提示',json.msg,'error');
				}					   
				$.messager.progress('close');
		}
	  });
}

//选择
function onClickAttribute(){

	$('#dlg').dialog('open');

}

//
function SelectBeasedata()
{
	var row = $('#element-basedata-table').treegrid('getSelected');			
	if (!row) {
				$.messager.alert('提示', '请选择需要启用数据字典!', 'info');
				return false;
	}
	$("#beasedata").textbox('setValue',row.id);
	$('#dlg').dialog('close');
}


	    //禁止按钮点击，选中数据后启用
		$('#element-basedata-table').treegrid({
			onLoadSuccess : function(row, data) {//加载
				$('#element-linkbutton-select').linkbutton('disable');									
			},
			onSelect : function(row) {//高亮选择							
				$('#element-linkbutton-select').linkbutton('enable');									
			}
		});
	
	        
	                        
</script>


</body>
</html>